<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: xajax.google_global.php 11 2013-09-21 11:43:11Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 11 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 11:43:11 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

include(DIR_WS_CLASSES.'class.google_taxonomy.php');
$google = new googleTaxonomy();

function get_new_dropdown() {
	global $google;
	$ajax = new xajaxResponse();
	$c = '<table width="100%" border="0" id="selection" style="margin-left:20px" cellpadding="4">
			<tr>
				<td class="google_cat" id="sub_select" width="1">
					'.draw_pull_down_menu('google', $google->get_dropdown_data(), '', 'onchange="xajax_get_next_cat(this.value, \'\')" style="width:380px" class="selections"').'
				</td>
			</tr>
		</table>';
	
	$ajax->assign('google_taxonomy', 'innerHTML', $c);
	$ajax->append('google_taxonomy', 'innerHTML', '<input type="hidden" name="" value="" id="short_path" />');
	$ajax->script('$("#GOOGLE_MERCHANT_GLOBAL").width(\'90%\')');
	
	return $ajax;
}

function get_next_cat($value = '', $parent = '') {
	$ajax = new xajaxResponse();
	
	if(!empty($parent)) {
		$path = explode('|', $parent);
		$path[] = $value;
	} else
		$path[] = $value;

	if(sizeof($path) == 1) {
		$c .= '<tr><td width="1">'.drop_down('', $value, true).draw_hidden_field('path_0', $value).'</td></tr>'."\n";
		$c .= '<tr><td width="1">'.drop_down($value).'</td></tr>'."\n";
		$ajax->script('$("#save_button").addClass("save_google_button_on");');
		
	} else {
		$long = implode(' > ', $path);
		for ($i = 0; $i < sizeof($path); $i++) {
			$np .= ($i > 0 && $path[$i -1]!='' ? ' > ' : '').$path[$i -1];
			$c .= '<tr><td width="1">'.drop_down(substr($np, strlen($path[$i -1])), $path[$i], true).'</td></tr>'."\n";
		}
		if(drop_down($long, '', $id))
			$c .= '<tr><td width="1">'.drop_down($long, '', $id).'</td></tr>'."\n";
	}
	
	$j  = '$("#short_path").val("'.implode('|', $path).'");';
	$j .= '$("#GOOGLE_MERCHANT_GLOBAL").val("'.implode(' > ', $path).'");';
	$ajax->script($j);
	$ajax->assign('selection', 'innerHTML', $c);
	
	return $ajax;
}

function drop_down($value = '', $default ='', $read_only = false) {
	global $google;
	$data = $google->get_dropdown_data($value);

	if(!empty($data)) {
		$d = draw_pull_down_menu('', $data, $default, ($read_only?'disabled="" ':'').'onchange="xajax_get_next_cat(this.value, $(\'#short_path\').val())" style="width:380px"');
		return $d;
	}
	return false;
}

$xajax->registerFunction('get_next_cat');
$xajax->registerFunction('reset_cat');
$xajax->registerFunction('get_new_dropdown');
?>